package com.ruoyi.labdata.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.labdata.mapper.LabClassRoomMapper;
import com.ruoyi.labdata.domain.LabClassRoom;
import com.ruoyi.labdata.service.ILabClassRoomService;

/**
 * 实验室地址Service业务层处理
 * 
 * @author winner pan
 * @date 2022-02-07
 */
@Service
public class LabClassRoomServiceImpl implements ILabClassRoomService 
{
    @Autowired
    private LabClassRoomMapper labClassRoomMapper;

    /**
     * 查询实验室地址
     * 
     * @param classRoomId 实验室地址ID
     * @return 实验室地址
     */
    @Override
    public LabClassRoom selectLabClassRoomById(Long classRoomId)
    {
        return labClassRoomMapper.selectLabClassRoomById(classRoomId);
    }

    /**
     * 查询实验室地址列表
     * 
     * @param labClassRoom 实验室地址
     * @return 实验室地址
     */
    @Override
    public List<LabClassRoom> selectLabClassRoomList(LabClassRoom labClassRoom)
    {
        return labClassRoomMapper.selectLabClassRoomList(labClassRoom);
    }

    /**
     * 新增实验室地址
     * 
     * @param labClassRoom 实验室地址
     * @return 结果
     */
    @Override
    @Transactional
    public int insertLabClassRoom(LabClassRoom labClassRoom){
    	if(labClassRoom.getDelRooms()!=null && labClassRoom.getDelRooms().length>0){
    		labClassRoomMapper.deleteLabClassRoomByIds(labClassRoom.getDelRooms());
    	}
    	for(String room : labClassRoom.getAddRooms()){
    		LabClassRoom classRoom = new LabClassRoom();
    		classRoom.setLabId(labClassRoom.getLabId());
    		classRoom.setClassRoom(room);
    		classRoom.setBuildingId(labClassRoom.getBuildingId());
    		labClassRoomMapper.insertLabClassRoom(classRoom);
    	}
        return 1;
    }

	
    /**
     * 修改实验室地址
     * 
     * @param labClassRoom 实验室地址
     * @return 结果
     */
    @Override
    public int updateLabClassRoom(LabClassRoom labClassRoom)
    {
        return labClassRoomMapper.updateLabClassRoom(labClassRoom);
    }

    /**
     * 批量删除实验室地址
     * 
     * @param classRoomIds 需要删除的实验室地址ID
     * @return 结果
     */
    @Override
    public int deleteLabClassRoomByIds(Long[] classRoomIds)
    {
        return labClassRoomMapper.deleteLabClassRoomByIds(classRoomIds);
    }

    /**
     * 删除实验室地址信息
     * 
     * @param classRoomId 实验室地址ID
     * @return 结果
     */
    @Override
    public int deleteLabClassRoomById(Long classRoomId)
    {
        return labClassRoomMapper.deleteLabClassRoomById(classRoomId);
    }
}
